subroutine recvpkt(nblock2,userx_no,kb,k,buf8,buf16)

! Reformat timf2 data from Linrad and stuff data into r*4 array dd().

  parameter (NSMAX=60*96000)          !Total sample intervals per minute
  integer*1 userx_no
  integer*2 nblock,nblock0
  logical first
  real*8 d8,buf8(174)
  complex*16 c16,buf16(87)
  integer*2 jd(4),nblock2
  real*4 xd(4)
  include 'datcom.f90'
  equivalence (jd,d8)
  equivalence (xd,c16)
  data nblock0/0/,ns00/99/,first/.true./
  data sqave/0.0/,rxnoise/0.0/,pctblank/0.0/,lost_tot/0/

  nblock=nblock2
  if(nblock2.lt.0) nblock=nblock+65536
  if(userx_no.lt.0) then
     nfloat=1
     iz=87
  else
     nfloat=0
     iz=174
  endif

  if(.not.first) then
! Check for lost packets
     lost=nblock-nblock0-1
     if(lost.ne.0) then
        nb=nblock
        if(nb.lt.0) nb=nb+65536
        nb0=nblock0
        if(nb0.lt.0) nb0=nb0+65536
        lost_tot=lost_tot + lost               ! Insert zeros for the lost data.
!###
!        do i=1,iz*lost
!           k=k+1
!           d8(k)=0
!        enddo
!###
     endif
  endif
  first=.false.
  nblock0=nblock

! Move data into Rx buffer and compute average signal level.
  sq=0.
  do i=1,iz
     k=k+1
     k2=k
     n=0
     if(k.gt.NSMAX) then
        k2=k2-NSMAX
        n=1
     endif

     if(nfloat.eq.0) then
        d8=buf8(i)
        x1=jd(1)
        x2=jd(2)
        x3=jd(3)
        x4=jd(4)
        dd(1,k2,n)=x1
        dd(2,k2,n)=x2
        dd(3,k2,n)=x3
        dd(4,k2,n)=x4
        sq=sq + x1*x1 + x2*x2 + x3*x3 + x4*x4
     else
        c16=buf16(i)
        x1=xd(1)
        x2=xd(2)
        x3=xd(3)
        x4=xd(4)
        dd(1,k2,n)=x1
        dd(2,k2,n)=x2
        dd(3,k2,n)=x3
        dd(4,k2,n)=x4
        sq=sq + x1*x1 + x2*x2 + x3*x3 + x4*x4
     endif
  enddo
  sq=sq/(2.0*iz)
  u=0.001
  if(nfloat.ne.1) u=2.0*u
  sqave=sqave + u*(sq-sqave)
  rxnoise=10.0*log10(sqave) - 20.0            ! Was -48.0
  kxp=k

  return
end subroutine recvpkt
